<?php
require("../class/connect.php");
require("../class/db_sql.php");
require("../class/functions.php");
require LoadLang("pub/fun.php");
require("../class/delpath.php");
require("../class/t_functions.php");
require("../data/dbcache/class.php");
require("../data/dbcache/MemberLevel.php");
require("../class/user.php");
require("../class/qinfofun.php");
$link=db_connect();
$empire=new mysqlquery();
$enews=$_POST['enews'];
if(empty($enews))
{$enews=$_GET['enews'];}
$muserid=(int)getcvar('mluserid');
$musername=RepPostVar(getcvar('mlusername'));
$mrnd=RepPostVar(getcvar('mlrnd'));
$loginin='[Member]'.$musername;
$doetran=1;
//增加投稿
if($enews=="MAddInfo")
{
	//echo __LINE__;
	//print_r($_REQUEST);
	//exit();
	DodoInfo($_POST,0);
}
//修改投稿
elseif($enews=="MEditInfo")
{
	DodoInfo($_POST,1);
}
//删除投稿
elseif($enews=="MDelInfo")
{
	DodoInfo($_GET,2);
}
//编辑器上传图片
elseif($enews=="MEditorTranFile")
{
	$file=$_FILES['file']['tmp_name'];
    $file_name=$_FILES['file']['name'];
    $file_type=$_FILES['file']['type'];
    $file_size=$_FILES['file']['size'];
	DoQTranFile($_POST,$file,$file_name,$file_type,$file_size,$muserid,$musername,$mrnd,1);
}
//上传附件
elseif($enews=="MTranFile")
{
	$file=$_FILES['file']['tmp_name'];
    $file_name=$_FILES['file']['name'];
    $file_type=$_FILES['file']['type'];
    $file_size=$_FILES['file']['size'];
	DoQTranFile($_POST,$file,$file_name,$file_type,$file_size,$muserid,$musername,$mrnd,0);
}elseif($enews=="exitTribe"){
	$tid=$_REQUEST['tid'];
	if($lguserid){
		exitTribe($lguserid,$tid);
	}else{
		
	}
	echo '<script>history.go(-1);</script>';
}elseif($enews=="add_tribe_word"){
	$_id		= $_REQUEST['tid'];
	$_t			= $_REQUEST['title'];
	$_content	= $_REQUEST['content'];

	$db='phome_ecms_tribe';
	$t_db='phome_jat_tribe_subject';
	
	if(empty($_id)){
		jatMessage('部落ID获取错误！');	
	}
	if(empty($lguserid)){
		jatMessage('用户未登录，不能提交话题！');	
	}
	if(empty($_t)){
		jatMessage('标题不能为空！');	///error;
	}
	if(empty($_content)){
		jatMessage('内容不能为空！');	///error;
	}
	$rs=DbTouch($db,array('id'=>$_id));
	if(!empty($rs)){
		$_t=sub($_t,0,50);
		$_content=sub($_content,0,3000);
		DbAdd($t_db,array(
							'uid'=>$lguserid,
							'tribe_id'=>$_id,
							'title'=>$_t,
							'content'=>$_content,
							'time'=>time(),
							'last_reply_time'=>time(),
			));
		jatMessage('添加成功！');	///error;
	}else{
		jatMessage('记录不存在！');	///error;
	}
}elseif($enews=='add_tribe_abm'){
		if(!$lguserid){jatMessage("用户未登录,不能创建相册！");}		
		$DB_ABLUM="phome_jat_album";
		$db_t='phome_ecms_tribe';
		///$num=DbTouch('phome_jat_album',array("uid"=>$lguserid),"count(*) as n");
		 //if($num>=DF_LIMIT_USER_ALB_NUM){
		//	show_error('您已经建立了$num[n]个专辑，不能再建立了！');
		 //}
		$tribe_id=$_REQUEST['tid'];
		$title=$_REQUEST["title"];
		$addr='部落相册';
		$permission=0;		
		$content=$_REQUEST["content"];
		$num=DbTouch($db_t,array('id'=>$tribe_id),'id');
		if(empty($num)){
			jatMessage('部落信息获取错误，创建失败！');
		}
		$arr=array(
					"uid"=>$lguserid,
					"title"=>enSafeContent(trim($title)),
					"addr"=>enSafeContent($addr),
					"content"=>enSafeContent($content),
					"type "=>TRIBE_ID_ROOT,
					'referer_id'=>$tribe_id,
					"permission"=>enSafeContent($permission),
					"time"=>time(),
					"status"=>1
				);	
		if($flag=DbAdd($DB_ABLUM,$arr)){
			jatMessage('创建成功！',$public_r['newsurl'].'tribe/detail/?id='.$tribe_id.'&m=u&abm_id='.$flag);
		}else{
			jatMessage("系统错误");
		}
}elseif($enews=='join_tribe'){
	$_id=(int)$_REQUEST['id'];
	$_type=(int)$_REQUEST['t'];
	if(empty($lguserid)){
		show_error('用户未登录不能加入！');
	}else if(empty($_id)){
		show_error('参数错误，不能加入！');
	}
	$db='phome_ecms_tribe';
	$db_join='phome_jat_jointribe';
	$rs=DbTouch($db,array('id'=>$_id));
	if(empty($rs)){
		show_error('记录不存在！');
	}
	$e=DbTouch($db_join,array('uid'=>$lguserid,'tid'=>$_id));
	if(!empty($e) && $_type==0){show_error('您已经加入了！');}
	if(empty($e) && $_type==1){show_error('您已经退出了！');}
	if($_type==0){
		$flag=DbAdd($db_join,array('uid'=>$lguserid,'tid'=>$_id,'time'=>time()));
		DbAddOne($db,array('id'=>$_id),'join_num');
		sendNews(JOIN_TRIBE_ID,$_id,0,array('id'=>$_id));
		show_succ('ok');
	}else if($_type==1){
		$flag=DbDelete($db_join,array('uid'=>$lguserid,'tid'=>$_id));
		DbLessOne($db,array('id'=>$_id),'join_num');
		show_succ('ok');
	}
	
}else{
	printerror("ErrorUrl","",1);
}
db_close();
$empire=null;
?>